cmake_minimum_required(VERSION 3.2)
project(CANopenLinux)

set(CMAKE_CXX_STANDARD 17)

set(DRV_SRC .)
set(CANOPEN_SRC CANopenNode)
set(APPL_SRC CANopenNode/example)

include_directories(
    ${DRV_SRC}
    ${CANOPEN_SRC}
    ${APPL_SRC}
)

add_library(
        canopen

        STATIC

        ${DRV_SRC}/CO_driver.c
        ${DRV_SRC}/CO_error.c
        ${DRV_SRC}/CO_epoll_interface.c
        ${DRV_SRC}/CO_storageLinux.c
        ${CANOPEN_SRC}/301/CO_ODinterface.c
        ${CANOPEN_SRC}/301/CO_NMT_Heartbeat.c
        ${CANOPEN_SRC}/301/CO_HBconsumer.c
        ${CANOPEN_SRC}/301/CO_Emergency.c
        ${CANOPEN_SRC}/301/CO_SDOserver.c
        ${CANOPEN_SRC}/301/CO_SDOclient.c
        ${CANOPEN_SRC}/301/CO_TIME.c
        ${CANOPEN_SRC}/301/CO_SYNC.c
        ${CANOPEN_SRC}/301/CO_PDO.c
        ${CANOPEN_SRC}/301/crc16-ccitt.c
        ${CANOPEN_SRC}/301/CO_fifo.c
        ${CANOPEN_SRC}/303/CO_LEDs.c
        ${CANOPEN_SRC}/304/CO_GFC.c
        ${CANOPEN_SRC}/304/CO_SRDO.c
        ${CANOPEN_SRC}/305/CO_LSSslave.c
        ${CANOPEN_SRC}/305/CO_LSSmaster.c
        ${CANOPEN_SRC}/309/CO_gateway_ascii.c
        ${CANOPEN_SRC}/storage/CO_storage.c
        ${CANOPEN_SRC}/extra/CO_trace.c
        ${CANOPEN_SRC}/CANopen.c
        ${APPL_SRC}/OD.c
)

target_include_directories(canopen PUBLIC
        "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
        "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")

find_package(Threads REQUIRED)

target_link_libraries(canopen PUBLIC Threads::Threads)

add_executable(
        canopend

        ${DRV_SRC}/CO_main_basic.c
)

target_link_libraries(
        canopend PUBLIC
        canopen
)